﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WebApplication3.Domain.Entity;

namespace WebApplication3.Domain
{
    public class DblnitializeHelper
    {
         public static void Initilizer()
        {
            using (var db=new Admin4000DbContext())
            {

                var no_repeat=db.Database.EnsureCreated();


                var tempBrand = db.Brand.Any();

                if (!tempBrand)//判断 不重复出现数据
                {
                    var brand = new Brand
                    {
                        BrandName = "phone",
                        Description = "手机"
                    };
                    db.Brand.Add(brand);
                    db.SaveChanges();

                    db.Proudcts.AddRange(new Proudct[]
                    {
                    new Proudct
                    {
                        ProductName="诺基亚",
                        ShortDesc="这是一个老年机",
                        FullDesc="90年代潮流",
                        BrandId=brand.id
                    },
                    new Proudct
                    {
                        ProductName="智能机",
                        ShortDesc="这也是一个手机",
                        FullDesc="风靡当代",
                        BrandId=brand.id
                    }
                    });
                    db.SaveChanges();
                }
                 
            }
        }
    }
}
